You have the following three vectors:

species <- c(
  "MountainBeaver",
  "Cow",
  "GreyWolf",
  "Goat",
  "GuineaPig",
  "Diplodocus",
  "AsianElephant",
  "Donkey",
  "Horse",
  "PotarMonkey",
  "Cat",
  "Giraffe",
  "Gorilla",
  "Human",
  "AfricanElephant",
  "Triceratops",
  "RhesusMonkey",
  "Kangaroo",
  "GoldenHamster",
  "Mouse",
  "Rabbit",
  "Sheep",
  "Jaguar",
  "Chimpanzee",
  "Rat",
  "Brachiosaurus",
  "Mole",
  "Pig"
)

bodywt_kg <- c(
  1.4,
  465,
  36.3,
  27.7,
  1.,
  11700,
  2547,
  187.1,
  521,
  10,
  3.3,
  529,
  207,
  62,
  6654,
  9400,
  6.8,
  35,
  0.1,
  0.02,
  2.5,
  55.5,
  100,
  52.2,
  0.3,
  87000,
  0.1,
  192
)

brainwt_kg <- c(
  0.0081,
  0.423,
  0.1195,
  0.115,
  0.0055,
  0.05,
  4.603,
  0.419,
  0.655,
  0.115,
  0.0256,
  0.68,
  0.406,
  1.32,
  5.712,
  0.07,
  0.179,
  0.056,
  0.001,
  0.0004,
  0.0121,
  0.175,
  0.157,
  0.44,
  0.0019,
  0.1545,
  0.003,
  0.18
)

Copy and paste the vectors into your R script and solve the following tasks.

animals_to_check <- c("Snail", "Goat", "Chimpanzee", "Rat", "Dragon", "Eagle")

1 For the fast ones

  • Round the ratio vector to 4 decimal places with the round function
    • Type ?round into the console to open the help of the round function
  • Which animal has the smallest brain to body weight ratio?
    • Hint: have a look at the min function
  • Add the following three animals to the data vectors
species_new <- c("Eagle", "Snail", "Lion")
brainwt_kg_new <- c(0.0004, NA, 0.5)
bodywt_kg_new <- c(18, 0.01, 550)

Now calculate the mean brain weight again. Can you explain what happens? Can you fix it?

  • Hint: have a look at ?mean